/**
 * Created by zhaoyanzhi on 16-9-8.
 */
app.controller('shoppingCartPageCtrl', function ($scope, $location){
    var goodsInfo=JSON.parse(localStorage.getItem("goodsInfo"))||{};
    $scope.cartList=goodsInfo.cartList;
    $scope.jumpHomePage=function(){
        $location.path("/")
    };
    $scope.jumpShoppingListPage= function(){
        $location.path("/productListPage")
    };
    $scope.showCartCount=function(){
        var shoppingCart =new ShoppingCart();
        var cartCount=shoppingCart.computeSumCount();
        $scope.cartCount = cartCount||0;
        if(cartCount==0){
            $scope.jumpShoppingListPage();
        }
    };
    $scope.jumpPaymentPage=function(){
       $location.path("/paymentPage")
    };
    $scope.showActuallyPaid=function(){
        var shoppingCart =new ShoppingCart();
        var sumActuallyPaid=shoppingCart.computeSumActuallyPaidPrice();
        $scope.actuallyPaid=sumActuallyPaid;
    }
    $scope.addButtonEvent=function(product,num){
        var control=new Control();
        var cartList=control.changeCartListInfoy(product,num);
        control.saveGoodsInfo(cartList);
        $scope.showCartCount();
        var goodsInfo=JSON.parse(localStorage.getItem("goodsInfo"))||{};
        $scope.cartList=goodsInfo.cartList;
        $scope.showActuallyPaid();
    }
});

